<?php

declare(strict_types=1);

namespace app\model\admin;

use app\model\AdminBaseModel;
use think\Model;

/**
 * @mixin \think\Model
 * 协议表
 */
class BalanceLog extends AdminBaseModel
{
    // 数据表名称
    protected $table = 'balance_log';
    protected $scopeField = true;

    //可搜索字段
    protected $searchField = [];
    // like
    protected $singleSearchField = [];
    //可作为条件的字段
    protected $whereField = ['status', 'is_operator', 'order_sn'];  //相等
    // protected $append = ['img_url'];
    //可做为时间范围查询的字段
    protected $timeField = ['created_at'];

    protected $append = ['profit_type_text'];


    public function user()
    {
        return $this->belongsTo(MiniUser::class, 'user_id', 'id');
    }
    public function fromUser()
    {
        return $this->belongsTo(MiniUser::class, 'from_user_id', 'id');
    }
    public function sysUser()
    {
        return $this->belongsTo(SysMember::class, 'user_id', 'id');
    }
    public function order()
    {
        return $this->belongsTo(Order::class, 'order_sn', 'order_sn');
    }
    public function getProfitTypeTextAttr($value, $data)
    {
        // $type = $this->attributes['profit_type'];
        // return $data['profit_type'];
        $map = [
            1 => "下级分润",
            2 => "满额度奖励(1000自身奖励)",
            3 => "满6笔数奖励(自身)",
            4 => "直推商户刷满2000奖励",
            5 => "间推商户刷满2000奖励",
            6 => "代理商获得直推商户刷满5000元奖励",
            7 => "代理商获取直推商户刷满20000元奖励",
            8 => "代理商获得间推商户刷满5000元奖励",
            9 => "提现",
        ];
        return $map[$data['profit_type']];
    }
}
